// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let openid = wxContext.OPENID
  let WillNUM = event.WillNum
  let changeIndex = event.index
  let changeID = event.cartID
  let Type = event.Type
  if(Type==0){
  return await cloud.database().collection('shopping-cart')
  .doc(changeID)
  .update({
    data:{
      ['goods.'+changeIndex+'.num']:WillNUM
    }
  })
 }else if(Type==1){
  return await cloud.database().collection('shopping-cart')
  .doc(changeID)
  .update({
    data:{
      ['goods.'+changeIndex+'.num']:_.inc(1)
    }
  })
 }else{
  return await cloud.database().collection('shopping-cart')
  .doc(changeID)
  .update({
    data:{
      ['goods.'+changeIndex+'.num']:_.inc(-1)
    }
  })
 }
}